﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;

namespace WebDataServer
{
    public class Sample
    {
        /// <summary>
        /// Base64文件上传
        /// </summary>
        /// <param name="url">ASMX服务URL</param>
        /// <param name="imagePath">路径</param>
        public static async void FileUpdata(string url, string filePath)
        {
            byte[] fileBytes = File.ReadAllBytes(filePath);
            string base64File = Convert.ToBase64String(fileBytes);
            HttpClient client = new HttpClient();
            var parameters = new Dictionary<string, string>
                                {
                                    { "base64Data", base64File },
                                    { "fileName", filePath }
                                };
            JavaScriptSerializer serializer = new JavaScriptSerializer() { MaxJsonLength=int.MaxValue };
            HttpContent content = new StringContent(serializer.Serialize(parameters), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync(url, content);
            string resultMsg = await response.Content.ReadAsStringAsync(); // 输出结果
            
        }
		
		public static async void HelloWorld()
        {
            string url = "https://localhost:44319/STXImageWebService.asmx/HelloWorld"; // 你的ASMX服务URL
            HttpClient client = new HttpClient();
            var content = new StringContent("", Encoding.UTF8, "application/json"); 
            var response = await client.PostAsync(url, content);
            string resultMsg = await response.Content.ReadAsStringAsync(); // 输出结果
            textBox_resultMsg.Text = resultMsg;

            label_timems.Text = "响应：" + sw.ElapsedMilliseconds + "ms";
            sw.Reset();
        }
    }
}